<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <meta name="twitter:site" content="@metroui">
    <meta name="twitter:creator" content="@pimenov_sergey">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="Metro 4 Components Library">
    <meta name="twitter:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta name="twitter:image" content="https://metroui.org.ua/images/m4-logo-social.png">

    <meta property="og:url" content="https://metroui.org.ua/v4/index.html">
    <meta property="og:title" content="Metro 4 Components Library">
    <meta property="og:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta property="og:type" content="website">
    <meta property="og:image" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:secure_url" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:width" content="968">
    <meta property="og:image:height" content="504">

    <meta name="author" content="Sergey Pimenov">
    <meta name="description" content="Need progress bar in the form of a donut? Use donut component to create it. The most popular HTML, CSS, and JS library in Metro style.">
    <meta name="keywords" content="HTML, CSS, JS, Metro, CSS3, Javascript, HTML5, UI, Library, Web, Development, Framework">

    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" href="favicon.ico" type="image/x-icon">

    <link href="metro/css/metro-all.css?ver=@@b-version" rel="stylesheet">
    <link href="highlight/styles/github.css" rel="stylesheet">
    <link href="docsearch/docsearch.min.css" rel="stylesheet">
    <link href="css/site.css" rel="stylesheet">

    <title>Donut - Metro 4 :: Popular HTML, CSS and JS library</title>
</head>
<body class="m4-cloak">

<header data-role="html-container" data-insert-mode="replace" data-html-source="header.html"></header>

<div data-role="html-container" data-insert-mode="replace" data-html-source="sidebar-menu.html"></div>

<div class="container-fluid docs-content">

    <div class="row flex-xl-nowrap">

            <div class="d-none d-block-xl cell-xl-2 order-2 border-left bd-light toc-wrapper">
                <h5>Table of contents</h5>
                <hr/>
                <ul class="toc-nav">
                    <li class="toc-entry"><a href="#">Donut</a></li>
                    <li class="toc-entry"><a href="#_donut_create">Create donut</a></li>
                    <li class="toc-entry"><a href="#_donut_value">Set &amp; get value</a></li>
                    <li class="toc-entry"><a href="#_donut_options">Options</a></li>
                    <li class="toc-entry"><a href="#_donut_events">Events</a></li>
                </ul>
            </div>

            <main class="cell-xl-10 order-1 pr-1-sx pl-1-sx pr-5-md pl-5-md">
                <div class="place-right d-none d-block-lg" style="width: 200px;">
                    <img src="images/logo.png" class="w-100" alt="">
                </div>

                <h1>Donut</h1>
                <p class="text-leader">
                    Need progress bar in the form of a donut? Use donut component to create it.
                </p>

                <!-- ads-html -->

                <h3 id="_donut_create">Create donut</h3>
                <p>
                    To create progress bar in the form of a donut add <code>data-role="donut"</code> to element. To set <code>value</code> use attribute <code>data-value="..."</code>.
                </p>
                <div class="example">
                    <div class="row">
                        <div class="cell-md-3">
                            <div class="mx-auto" id="donut1" data-role="donut" data-value="35" data-show-value="true" data-cap=""></div>
                        </div>
                        <div class="cell-md-3">
                            <div class="mx-auto" id="donut2" data-role="donut" data-value="35" data-hole="0" data-stroke="transparent" data-fill="#4CAF50" data-animate="500"></div>
                        </div>
                        <div class="cell-md-3">
                            <div class="mx-auto" id="donut3" data-role="donut" data-value="35" data-hole=".6" data-stroke="#f5f5f5" data-fill="#9C27B0" data-animate="500"></div>
                        </div>
                        <div class="cell-md-3">
                            <div class="mx-auto" id="donut4" data-role="donut" data-value="35" data-stroke="#F44336" data-fill="#FFC107" data-color="#FFFFFf" data-cap="" data-animate="500" data-background="#4fc3f7" data-font-size="32"></div>
                        </div>
                    </div>
                </div>
                <pre><code>
                    &lt;div id="donut1" data-role="donut" data-value="35"&gt;&lt;/div&gt;

                    &lt;div id="donut2" data-role="donut" data-value="35"
                        data-hole="0" data-stroke="transparent"
                        data-fill="#4CAF50" data-animate="10"&gt;&lt;/div&gt;

                    &lt;div id="donut3" data-role="donut" data-value="35"
                        data-hole=".6" data-stroke="#f5f5f5" data-fill="#9C27B0"
                        data-animate="10"&gt;&lt;/div&gt;

                    &lt;div id="donut4" data-role="donut" data-value="35"
                        data-stroke="#F44336" data-fill="#FFC107" data-color="#FFFFFf"
                        data-cap="" data-animate="10" data-background="#4fc3f7"
                        data-font-size="32"&gt;&lt;/div&gt;
                </code></pre>

                <h3 id="_donut_value">Set and get value</h3>
                <p>
                    To set or get <code>value</code> you can use component method <code>val()</code>. Also you can set value at runtime with attribute <code>data-value</code>.
                </p>
                <div class="example">
                    <div id="donut_val" data-role="donut" data-value="35" class="mx-auto"></div>
                    <br>
                    <button class="button" onclick="setDonutNewValue()">Set new value</button>
                    <button class="button" onclick="getDonutValue()">Get value</button>
                </div>
                <pre><code>
                    &lt;div id="donut_val" data-role="donut" data-value="35" class="mx-auto"&gt;&lt;/div&gt;

                    &lt;button class="button" onclick="setDonutNewValue()"&gt;Set new value&lt;/button&gt;
                    &lt;button class="button" onclick="getDonutValue()"&gt;Get value&lt;/button&gt;

                    &lt;script&gt;
                        function setDonutNewValue(){
                            var donut = $('#donut_val').data('donut');
                            donut.val($.random(0, 100));
                        }

                        function getDonutValue(){
                            var donut = $('#donut_val').data('donut');
                            alert(donut.val());
                        }
                    &lt;/script&gt;
                </code></pre>

                <!-- ads-html -->

                <h3 id="_donut_options">Options</h3>
                <p>
                    Donut component has a number of options. You can use that options to set style and behavior of component.
                </p>
                <table class="table cell-border table-border options-table">
                    <thead>
                    <tr>
                        <th>Options</th>
                        <th>Data-*</th>
                        <th>Default</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>size</td>
                        <td>data-size</td>
                        <td>100</td>
                        <td>The width of component</td>
                    </tr>
                    <tr>
                        <td>radius</td>
                        <td>data-radius</td>
                        <td>50</td>
                        <td>The radius of donut</td>
                    </tr>
                    <tr>
                        <td>hole</td>
                        <td>data-hole</td>
                        <td>.8</td>
                        <td>The hole size (from 0 to 1)</td>
                    </tr>
                    <tr>
                        <td>value</td>
                        <td>data-value</td>
                        <td>0</td>
                        <td>The donut value</td>
                    </tr>
                    <tr>
                        <td>background</td>
                        <td>data-background</td>
                        <td>#ffffff</td>
                        <td>The donut background color</td>
                    </tr>
                    <tr>
                        <td>color</td>
                        <td>data-color</td>
                        <td>#000000</td>
                        <td>The donut text color</td>
                    </tr>
                    <tr>
                        <td>stroke</td>
                        <td>data-stroke</td>
                        <td>#d1d8e7</td>
                        <td>The donut value stroke color</td>
                    </tr>
                    <tr>
                        <td>fill</td>
                        <td>data-fill</td>
                        <td>#49649f</td>
                        <td>The donut value background color</td>
                    </tr>
                    <tr>
                        <td>fontSize</td>
                        <td>data-font-size</td>
                        <td>24</td>
                        <td>The donut text font size (in px)</td>
                    </tr>
                    <tr>
                        <td>total</td>
                        <td>data-total</td>
                        <td>100</td>
                        <td>The maximum of donut value</td>
                    </tr>
                    <tr>
                        <td>cap</td>
                        <td>data-cap</td>
                        <td>%</td>
                        <td>Additional caption for donut text</td>
                    </tr>
                    <tr>
                        <td>animate</td>
                        <td>data-animate</td>
                        <td>0</td>
                        <td>Animation factor (from 0 to 10)</td>
                    </tr>
                    <tr>
                        <td>showValue</td>
                        <td>data-show-value</td>
                        <td>false</td>
                        <td>if true, value is displayed, false - display percent </td>
                    </tr>
                    </tbody>
                </table>

                <h3 id="_donut_events">Events</h3>
                <p>
                    When donut works, it generated the numbers of events. You can use callback for this event to behavior with donut.
                    Rules for working with events are described on <a href="events.html">this page</a>.
                </p>
                <table class="table cell-border table-border options-table">
                    <thead>
                    <tr>
                        <th>Event</th>
                        <th>Data-*</th>
                        <th>Default</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>onChange(val, el)</code></td>
                        <td><code>data-on-change</code></td>
                        <td>Metro.noop</td>
                        <td>Callback for value change</td>
                    </tr>
                    <tr>
                        <td><code>onDonutCreate(el)</code></td>
                        <td><code>data-on-donut-create</code></td>
                        <td>Metro.noop</td>
                        <td>Callback fired when donut is created</td>
                    </tr>
                    </tbody>
                </table>
                <pre><code>
                    &lt;div data-role="donut"
                        data-value="35"
                        data-on-donut-create="console.log('Donut was created!')"
                        data-on-change="console.log(arguments)"
                    &gt;&lt;/div&gt;
                </code></pre>

            </main>
        </div>

    </div>

    <script src="docsearch/docsearch.min.js"></script>


    <script src="metro/js/metro.js?ver=@@b-version"></script>
    <script src="highlight/highlight.pack.js"></script>
    <script src="js/clipboard.min.js"></script>
    <script src="js/site.js"></script>

    <script>
        var donut_interval = null;
        (function(){
            clearInterval(donut_interval);
            donut_interval = setInterval(function(){
                var i, d;
                for (i = 0; i < 4; i++) {
                    d = $.random(0,100);
                    Metro.getPlugin('#donut'+(i+1), 'donut').val(d);
                }
            }, 2000);
        })();

        function setDonutNewValue(){
            var donut = $('#donut_val').data('donut');
            donut.val($.random(0, 100));
        }

        function getDonutValue(){
            var donut = $('#donut_val').data('donut');
            alert(donut.val());
        }
    </script>

    <!-- ads-script -->
    <!-- ga-script -->
    <!-- hit-ua -->
</body>
</html>